<template>
	<view class="wrapper">
		<image src="../../static/money/win.png" class="win" v-if="info.status!=3"></image>
		<image src="../../static/money/warning.png" class="warning" v-if="info.status==3"></image>
		<view class="get_money">
			<!-- <text v-if="st">{{info.userName}}</text> -->
			<text>{{info.status | status}}</text>
		</view>
		
		<view class="total_box">
			<text>￥</text>
			{{info.money}}
		</view>
		<view class="tCenter c666 f20 timeAlert" v-if="myinfo.userId==info.toUserId&&info.status==1">1天内未领取，将退还给对方</view>
		<view class="tips" v-if="myinfo.userId!=info.toUserId&&info.status==2">已存入对方零钱</view>
		<view class="tips jump" v-if="myinfo.userId==info.toUserId&&info.status==2" @tap="$open('../user/user_wallet')">查看零钱</view>
		<view class="cfff center f26 btn" v-if="myinfo.userId==info.toUserId&&info.status==1" @tap="receiveTransfer()">
			确认收款
		</view>
		<view class="give_time tCenter">
			<text>转账时间：</text>
			<text>{{info.createTime | time}}</text>
		</view>
		<view class="get_time tCenter" v-if="info.outTime&&info.status==2">
			<text>收钱时间：</text>
			<text>{{info.outTime | time}}</text>
		</view>
		<view class="get_time tCenter" v-if="info.status==3">
			<text>退还时间：</text>
			<text>2020-03-12 20:30:17</text>
		</view>
	</view>
</template>

<script>
import WEBIM from '@/common/webim.js';
import md5 from '@/common/md5.min.js'
export default {
	data() {
		return {
			id:'',
			info:'',
			myinfo:uni.getStorageSync('userinfo')
		};
	},
	onLoad(e) {
		this.id=JSON.parse(e.id).objectId
		this.getTransferInfo()
	},
	methods: {
		// 确认收款
		receiveTransfer(){
			let that = this,
				time=parseInt(new Date().getTime()/1000 ),
				userid=uni.getStorageSync('userinfo').userId,
				token=uni.getStorageSync('userinfo').access_token
			this.$ajax(this.apiList.receiveTransfer, {
				id: this.id,
				secret:md5(md5(this.apikey+time)+userid+token),
			}).then(res => {
				this.$sToast('领取成功')
				// 发送已领取
				var msg = WEBIM.createMessage(88, this.id, this.info.toUserId, this.info.userName, 'chat');
				msg.id = msg.messageId;
				WEBIM.sendMessage(msg);
				this.$back(1,1500)
			});
		},
		// 查询转账详情
		getTransferInfo() {
			this.$ajax(this.apiList.getTransferInfo, {
				id: this.id
			}).then(res => {
				// status 1 未领取 2已领取 3超时
				this.info = res.data;
			});
		}
	},
	filters:{
		status(value){
			if(value==1){
				return '待确认收款'
			}else if(value==2){
				return '已收钱'
			}else{
				return '已退还(过期)'
			}
		}
	}
};
</script>

<style>
	.warning{
		width: 94rpx;
		height: 94rpx;
		margin:28rpx 0 65rpx 0;
	}
	.btn{
		width:690rpx;
		height:80rpx;
		background:rgba(241,76,46,1);
		border-radius:4rpx;
		margin-top: 30rpx;
	}
	.wrapper{
		background:rgba(242,243,245,1);
		display: flex;
		flex-direction:column;
		align-items: center;
	}
	.win{
		width: 94rpx;
		height: 94rpx;
		margin:28rpx 0 65rpx 0;
	}
	.get_money{
		font-size:28rpx;
		font-weight:500;
		color:rgba(51,51,51,1);
	}
	.total_box{
		font-size:72rpx;
		font-weight:bold;
		color:rgba(51,51,51,1);
		margin: 49rpx 0 65rpx 0;
	}
	.tips{
		font-size:24rpx;
		font-weight:500;
		color:rgba(153,153,153,1);
	}
	.give_time{
		font-size:24rpx;
		font-weight:500;
		color:rgba(153,153,153,1);
		position: fixed;
		bottom: 142rpx;
		width: 100%;
	}
	.get_time{
		font-size:24rpx;
		font-weight:500;
		color:rgba(153,153,153,1);
		position: fixed;
		bottom: 100rpx;
		width: 100%;
	}
</style>
